#include "fupdate.h"
#if FUPDATE_USING_QUICKLZ

#include <quicklz.h>

void *rbl_quicklz_decompress_context_create(void)
{
	qlz_state_decompress * quicklz_decom_ctx  = rt_calloc(1, sizeof(qlz_state_decompress));
	rt_memset((uint8_t *)quicklz_decom_ctx, 0, sizeof(qlz_state_decompress));
	return quicklz_decom_ctx;
}
void rbl_quicklz_decompress_context_delete(void *quicklz_decom_ctx)
{
	rt_free(quicklz_decom_ctx);
}

uint32_t rbl_quicklz_decompress_get_block_size(void *quicklz_decom_ctx,const uint8_t *compress_datas)
{
	uint32_t block_size = 0;
	for (int i = 0; i < FUPDATE_QUICKLZ_HEADER_SIZE; i++)
	{
		block_size <<= 8;
		block_size += compress_datas[i];
	}
	return (block_size);
}

uint32_t rbl_quicklz_decompress_data(void *quicklz_decom_ctx, uint8_t *out_buf, const uint8_t *in_buf)
{
	qlz_state_decompress *quicklz_decompress_ctx = quicklz_decom_ctx;
	return (qlz_decompress((char *)in_buf, out_buf, quicklz_decompress_ctx));
}

#endif
